#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time   : 2023/7/25 15:28
# @title  : 激活push群组
# @Author : Demo
import os

import requests

from commit import read_yaml
token = os.getenv("PUSH_PLUS_TOKEN")
secretKey = os.getenv("PUSH_PLUS_USER")
url='https://www.pushplus.plus/api/common/openApi/getAccessKey'
data={
    "token": token,
    "secretKey": secretKey
}
res=requests.post(url,json=data)
print(res.json())
accessKey=res.json()["data"]["accessKey"]

# url="https://www.pushplus.plus/api/open/message/list"
# headers={
#     "Content-Type": "application/json",
#     "access-key":accessKey
# }
# res1=requests.post(url,headers=headers)
# print(res1.json())
def topic():
    url="https://www.pushplus.plus/api/open/topic/list"
    headers={
        "Content-Type": "application/json",
        "access-key":accessKey}
    data={
        "current": 1,
        "pageSize": 20,
        "params": {
            "topicType": 0
        }
    }
    res=requests.post(url,json=data,headers=headers)
    print(res.json())
# a=era(17607936763)
# a.lowerPrice()
def send(title,id,value):
    url="http://www.pushplus.plus/send"
    headers={
        "Content-Type": "application/json"}
    data={
        "token": "91a24d6e817a4ed8a3fc1287dde77293",
        "title": title,
        # "content":a.collectionNames,
        "content":value,
        "topic":id
    }
    res=requests.post(url,headers=headers,json=data)
    print(res.json())

def join():
    url="https://www.pushplus.plus/api/open/topic/qrCode"
    headers={
        "Content-Type": "application/json",
        "access-key":accessKey}
    data={
        "topicId":32952,
        "forever":1
    }
    res=requests.get(url,headers=headers,params=data)
    print(res.json())

if __name__ == '__main__':
    topic()
    join()
    # send()

